2
2
.
.
1
1
3
3
.
.
1
1
A
A
s
s
s
s
i
i
g
g
n
n
P
P
r
r
o
o
f
f
i
i
l
l
e
e
-
-
T
T
o
o
C
C
l
l
a
a
s
s
s
s
I
I
n
n
f
f
o
o
[
[
R
R
]
]
This tutorial shows how to assign Profiles to Classes by specifying for which
Profile to include Class @Profile("Profile1")
Profile to exclude Class @Profile("!Profile1")
Profiles to include/exclude Class @Profile({"Profile1", "!Profile2"})
Classes for which Profile is not assigned are always included in the application.
Assigning Profile to a Class is used in combination with @Autowired on Interface to tell Spring which Class to instantiate.
Such usage is demonstrated in tutorial Interface - @Profile.
application.properties (specify active Profile)
spring.profiles.active = Profile1
MyServiceImplementation1.java (assign Profile to Class)
@Profile( "Profile1" )
@Profile({"Profile2","Profile3"})
public class MyServiceImplementation1 implements MyServiceInterface { ... }
MyController.java (instantiate included Implementation/Class)
@Autowired
MyServiceInterface myService;